package com.yl.ydk.ui.activity

import android.content.Intent
import android.os.Build
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.RequiresApi
import com.yl.ydk.R
import com.yl.ydk.base.BaseActivity
import com.yl.ydk.presenter.contract.SiteAricleDetailActivityContract
import com.yl.ydk.presenter.impl.SiteAricleDetailActivityImpl
import com.blankj.utilcode.utils.ToastUtils
import kotlinx.android.synthetic.main.activity_site_aricle_detail.*
import kotlinx.android.synthetic.main.roob_bar.*

class SiteAricleDetailActivity : BaseActivity(), SiteAricleDetailActivityContract.View,
    View.OnClickListener {

    private val mPresenter = SiteAricleDetailActivityImpl()

    override fun getLayoutId(): Int = R.layout.activity_site_aricle_detail

    override fun attachView() {
        mPresenter.attachView(this)
    }

    override fun detachView() {
        mPresenter.detachView()
    }

    @RequiresApi(Build.VERSION_CODES.N)
    override fun initView() {

        tvTitle.text = "急救手册"
        rlSearch.visibility = View.VISIBLE
        rlBack.setOnClickListener(this)
        rlSearch.setOnClickListener(this)

        val id = intent.getStringExtra("data")
        mPresenter.getSiteAricleDetail(this, "id", id)

    }

    override fun getTvContent(): TextView = tvContent

    override fun getTvName(): TextView = tvName

    override fun getActivity(): SiteAricleDetailActivity = this

    override fun getIvUrl(): ImageView  = ivUrl

    override fun showError(message: String?) {
        ToastUtils.showLongToastSafe(message)
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.rlBack -> {
                finish()
            }
            R.id.rlSearch -> {
                startActivityIn(Intent(this, SiteArticleSearchActivity::class.java), this)
                finish()
            }
        }
    }

}